package com.eternal.permission.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.eternal.Exception.ResultEnum;
import com.eternal.Exception.ResultException;
import com.eternal.permission.entity.RoleInfo;
import com.eternal.permission.dao.RoleInfoMapper;
import com.eternal.permission.entity.enums.IsOpenEnum;
import com.eternal.permission.service.RoleInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import lombok.extern.java.Log;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 基础角色表 服务实现类
 * </p>
 *
 * @author Eternal
 * @since 2018-08-26
 */
@Service
@Primary
@Log
@Transactional
public class RoleInfoServiceImpl extends ServiceImpl<RoleInfoMapper, RoleInfo> implements RoleInfoService {


    @Override
    public Page<RoleInfo> getRoleInfo(Page<RoleInfo> page) {
        Page<RoleInfo> roleInfoPage = this.selectPage(page);
        return roleInfoPage;
    }

    @Override
    public RoleInfo getRoleInfo(String roleId) {
        RoleInfo roleInfo = this.selectById(roleId);
        return roleInfo;
    }

    @Override
    public int modifyIsOpen(RoleInfo roleInfo) {
        try {
            int update = this.baseMapper.updateById(roleInfo);
            return update;
        } catch (Exception e) {
            log.warning(e.getMessage());
            throw new ResultException(ResultEnum.UPDATE_ROLE_ISOPEN_ERROR);
        }


    }
}
